package ru.pachkun.home.logic;

import java.util.List;

import ru.pachkun.home.logicinterface.FilmHelperInterface;
import ru.pachkun.home.model.Film;

public class FilmHelper extends DriverBasedHelper implements
		FilmHelperInterface {

	public FilmHelper(ApplicationManager manager) {
		super(manager.getWebDriver());
	}

	@Override
	public void createFilm(Film film) {
		pages.internalPage.clickAddFilmLink().ensurePageLoaded()
				.setName(film.getTitle())
				.setYear(film.getYear())
				.setLanguages(film.getLanguages())
				.setPlots(film.getPlots())
				.clickSaveSubmitButton();
	}

	@Override
	public void deleteFilm(String id) {
		pages.internalPage
			.clickFilmById(id)
			.ensurePageLoaded()
			.clickRemoveFilm();
	}

	@Override
	public List<Film> search(String title) {
		pages.internalPage.Search(title);
		return pages.internalPage.takeAllSearchFilm();
	}
	
	@Override
	public Boolean isNotFilmFound() {
		return pages.internalPage.isNotFilmForSearch();
	}

	@Override
	public Boolean isErrorOnAddFilmPage() {
		return pages.addFilmPage.isError();
	}

	@Override
	public Boolean isNotSaveFilm() {
		return pages.addFilmPage.waitPageLoaded();
	}

	@Override
	public Boolean isSaveFilm() {
		return pages.filmInfoPage.waitPageLoaded();
	}
	
	@Override
	public Boolean isSearchFilmById(String id) {
		return pages.internalPage.isSearchFilmById(id); 
	}
}
